// This is a singleton class; use it like this:  StopStatuses.isStop('abc');
// It will only query the DB once per script, when first invoked.  If you need 
// to refresh it, call refresh after you change the db.
public class StopStatuses {
	class SafeString {
		public String str { get; private set; }
		public SafeString(String s) { this.str = ((s==null) ? '' : s); } 
	}
	public static testMethod void testSafeString() {
		system.assert(new SafeString(null).str == '');
		system.assert(new SafeString('').str == '');
		system.assert(new SafeString('xyz').str == 'xyz');
	}
		
    Set<String> allStopsLowerCased = new Set<String>();
    static StopStatuses inst = new StopStatuses();
    
    StopStatuses() {
        List<Stop_Status__c> sobjStops = [Select Name From Stop_Status__c];
        for(Stop_Status__c ss:sobjStops) {
            allStopsLowerCased.add(ss.Name.toLowerCase());
        }
    }
    
    public static boolean isStop(String status) {
        string s = (new SafeString(status)).str.toLowerCase();
        //integer cnt = [Select Count() From Stop_Status__c Where Name=:s];
        //return (cnt==0);
        return inst.allStopsLowerCased.contains(s);
    }
    
    public static void refresh() {
        inst = new StopStatuses();
    }
    
    public static testMethod void testIsStop() {
        StopStatuses.isStop('abc');
        StopStatuses.refresh();
    }
}